package com.supermap.rootstock.common.security.component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.supermap.rootstock.common.core.constant.CommonConstants;
import com.supermap.rootstock.common.security.exception.RootstockAuth2Exception;
import lombok.SneakyThrows;

/**
 * @author Robby
 * @date 2019/2/1
 * <p>
 * OAuth2 异常格式化
 */
public class RootstockAuth2ExceptionSerializer extends StdSerializer<RootstockAuth2Exception> {
	public RootstockAuth2ExceptionSerializer() {
		super(RootstockAuth2Exception.class);
	}

	@Override
	@SneakyThrows
	public void serialize(RootstockAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
		gen.writeStartObject();
		gen.writeObjectField("code", CommonConstants.FAIL);
		gen.writeStringField("msg", value.getMessage());
		gen.writeStringField("data", value.getErrorCode());
		gen.writeEndObject();
	}
}
